<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link href="<?=domain?>static/style/manage.css" rel="stylesheet" type="text/css" />
<link href="<?=domain?>static/style/fancybox.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?=domain?>static/scripts/core.js" charset="utf-8"></script>
<script type="text/javascript" src="<?=domain?>static/scripts/fancybox.js" charset="utf-8"></script>
<script type="text/javascript" src="<?=domain?>static/scripts/manage.js" charset="utf-8"></script>
<script type="text/javascript" src="<?=domain?>static/scripts/swfupload.js" charset="utf-8"></script>
<title><?=name?></title>
<body>
<div class="boxtitle">编辑广告</div>
<div class="area box">
<form name="edit" method="post" action="<?=domain?>index.php?c=advertise&a=edit" onsubmit="return check();">
<input type="hidden" name="id" value="<?=$advertiser['id']?>"/>
	<div class="line">
		<div class="w m">展示形式</div>
		<div class="s h select" change="SelectRestrict">
			<a href="javascript:void();"><label>请选择展示形式...</label><span></span></a>
	        <ul class="limit">
	          <?php
	          foreach($modality as $key=>$value){
	          ?>
		   	  <li tab="<?=$value['id']?>"<?=($value['id']==$advertiser['modality']['parent']?' selected':'')?>><a href="#"><?=$value['name']?></a></li>
			  <?php
			  }
	          ?>
		   	</ul>
		</div>
		<div class="e c"><font color="red">*</font>投放时展示的方式.</div>
	</div>
	<div class="line">
		<div class="w m">名称</div>
		<div class="s h"><input type="text" name="name" value="<?=$advertiser['name']?>" maxlength="32"/></div>
		<div class="e c"><font color="red">*</font>广告名称.</div>
	</div>
	<div class="line">
		<div class="w m">链接到</div>
		<div class="s h"><input type="text" name="link" value="<?=isset($advertiser['link'])?urldecode($advertiser['link']):'http://'?>" maxlength="255"/></div>
		<div class="e c"><font color="red">*</font>点击后到达地址.</div>
	</div>
	<div class="line">
		<div class="w m">尺寸</div>
		<div class="s h select" id="modality">
			<a href="javascript:void();"><label>请选择尺寸大小...</label><input type="hidden" name="modality" value="<?=$advertiser['modality']['id']?>"/><span></span></a>
	        <ul>
	          <?php
	          foreach($modality as $value){
	          	if($advertiser['modality']['parent']!=$value['id']){continue;}
	          	foreach($value['child'] as $v){
	          ?>
		   	  <li tab="<?=$v['id']?>"<?=($v['id']==$advertiser['modality']['id']?' selected':'')?>><a href="#"><?=$v['name']?></a></li>
			  <?php
			  }}
	          ?>
	        </ul>
		</div>
		<div class="e c"><font color="red">*</font>素材显示的尺寸.</div>
	</div>
	<div class="line">
		<div class="w m">素材类型</div>
		<div class="g">
			  <?php
	          foreach($format as $key=>$value){
	          ?>
	          <label><input type="radio" name="format" value="<?=$value['id']?>" <?=($advertiser['format']==$value['id']?' checked':'')?>><span><?=$value['name']?></span></label>
			  <?php
			  }
	          ?>
		</div>
		<div class="e c"><font color="red">*</font>素材格式.</div>
	</div>
	<div class="line">
		<div class="w m">素材链接</div>
		<div class="s h">
			<div id="progress" class="in up" style="width:66%;text-align:left;"></div>
			<div class="yellow up upload"><div id="upload"></div></div>
		    <input type="hidden" name="material" value="<?=$advertiser['material']?>"/>
		</div>
		<div class="e c"><font color="red">*</font>素材地址.</div>
	</div>
	<div class="line">
		<div class="w m">即刻投放</div>
		<div class="g">
			<label><input type="radio" name="online" value="1"<?=($advertiser['online']==1?' checked':'')?>><span>投放</span></label>
			<label><input type="radio" name="online" value="0"<?=($advertiser['online']==0?' checked':'')?>><span>暂停</span></label>
		</div>
		<div class="e c"><font color="red">*</font>是否即刻投放</div>
	</div>
</div>
<div class="boxbu">
	<input type="submit" name="save" value="确定" class="yellow"/>
</div>
</form>
</body>
</html>
<script language="JavaScript" type="text/javascript">
var modality=<?=json_encode($modality)?>;
function SelectRestrict(select){
	var obj=$('#modality');
	var select=$(select).attr('tab');
	if(obj.find('input[name="modality"]').attr('value')!='0'){
		obj.find('label').text('请选择尺寸大小...');
		obj.find('input').attr('value',0);
	}
	var html='';
	for(key in modality){
		if(modality[key]['id']==select){
			for(k in modality[key]['child']){
				html+='<li tab="'+modality[key]['child'][k]['id']+'"><a href="#">'+modality[key]['child'][k]['name']+'</a></li>';
			}
			break;
		}
	}
	obj.find('ul').addClass('limit').html(html);
	InitSelect('[id="modality"]');
}
var swfu=null;
$(document).ready(function(){
	var settings={
		flash_url : "<?=domain?>static/scripts/swfupload.swf",
		upload_url: "<?=domain?>index.php?c=advertise&a=edit&action=upload",
		post_params:{"<?=$session[0]?>":"<?=$session[1]?>"},
		file_post_name:'material',
		file_size_limit:"1MB",
		file_types:"*.jpg;*.gif;*.png;*.html;*.htm;*.swf",
		file_types_description:'.jpg,.gif,.png,.html,.htm,.swf',
		file_upload_limit:100,
		file_queue_limit:1,
		custom_settings:{
			progressTarget:"progress"
		},
		button_width:"100%",
		button_height:"23px",
		button_placeholder_id:"upload",
		button_action:SWFUpload.BUTTON_ACTION.SELECT_FILE,
		button_text:'<span class="button">上传...</span>',
		button_text_style:".button{font-size:14px;color:#FFFFFF;font-weight:bold;text-align:left;cursor:pointer;}",
		button_window_mode:SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor:-2,
		upload_progress_handler:material.progress,
		file_dialog_complete_handler:material.select,
		upload_success_handler:material.complete
	};
	swfu=new SWFUpload(settings);
});
var material={
	progress:function(file,bytesLoaded,bytesTotal){
		var percent=Math.ceil((bytesLoaded/bytesTotal)*100);
		$('#progress').html('<div style="width:'+percent+'%;height:18px;background-color:#A6C0E5;text-align:right;padding-top:5px;margin:0px;font-size:12px;">'+percent+'%</div>');
	},
	select:function(selected,queued){
		selected=swfu.getFile(0);
		if(selected!=null){
			if((selected.size/(1024*1024*1024))<=1){
				swfu.startUpload();
			}else{
				alert('上传文件不可超过1MB.');
			}
		}
	},
	complete:function(file,json){
		eval('json='+json+';');
		if(json['result']==0){
			$('input[name="material"]').attr('value',json['material']);
			$('#progress').text(file['name'].slice(0,10)+'...'+file['type']);
		}else{
			$('#progress').text(json['msg']);
		}
	}
};
function check(){
	if($('input[name="material"]').attr('value')==''){
		alert('未选择素材文件或未上传完毕.');
		return false;
	}else{
		return RequestPost('edit');
	}
}
</script>